package com.ece.pfe_rover_pvt_ines_ece_application;

import android.app.Application;

import com.ece.pfe_rover_pvt_ines_ece_application.model.Measurements;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseObject;
import com.parse.ParseRole;
import com.parse.ParseUser;

/**
 * Launch Application
 * NB. : For Parse anonymous fonctions, they are disabled on parse.com settings.
 * @author mathieubakrim
 *
 */
public class PFE_ROVER_PVT_INES_ECE_Application extends Application {
	
	public static final boolean DEBUG = true;
	public static final String ADMIN_ID = "v865h6ZzKz";
	
	public static final String MEASUREMENTS_GROUP_NAME = "ALL_MEASUREMENTS";
	public static final String ROLE_ON_SIGN_UP = "registered";
	
	// if false --> java null pointer exception MesureActivity.java:105
	// to debug
	public static final boolean ANONYMOUS_USERS_ALLOWED = false; 
	public static final boolean PUBLIC_READ_ACCESS_ALLOWED = true;
	public static final boolean PUBLIC_WRITE_ACCESS_ALLOWED = false;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		// add Measurements subclass
		ParseObject.registerSubclass(Measurements.class);
		
		// enable the Local Datastore
		Parse.enableLocalDatastore(getApplicationContext());
		
		// Register the application on PARSE project & online database
		Parse.initialize(this, "LNdQGGqdyyOjECPWmDnDcIln5SaTCzRnOcCiCjlv", "w000kASlE5IBDOtpEZXd9t9xK3Sbfnht0mE8UtDr");
		
		// Allow anonymous users to access the application
		if (ANONYMOUS_USERS_ALLOWED) {
			if(PFE_ROVER_PVT_INES_ECE_Application.DEBUG) System.out.println("//!\\ ---- enableAutomoaticUser...");
			ParseUser.enableAutomaticUser();
			
		}
		
		// ACLS - control read & write access for users
		ParseACL defaultACL = new ParseACL();
		defaultACL.setPublicReadAccess(PUBLIC_READ_ACCESS_ALLOWED);
		defaultACL.setPublicWriteAccess(PUBLIC_WRITE_ACCESS_ALLOWED);
		ParseACL.setDefaultACL(defaultACL, true);									
	}
}
